package com.bigflexlib.core.comparison.simple
{
	
	import com.bigflexlib.core.comparison.result.Bigger;
	import com.bigflexlib.core.comparison.result.ComparisonResult; import com.bigflexlib.core.comparison.result.ComparisonResults;
	import com.bigflexlib.core.comparison.result.Equal;
	import com.bigflexlib.core.comparison.result.Smaller;	
	
	/**
	 * 
	 * A quick way to create a comparator based on a compare function at runtime
	 * 
	 * @author aldo.bucchi@gmail.com
	 * 
	 */	
	public class DynamicSimpleComparator implements ISimpleComparator
	{
		
		private var compareFunction:Function;
		
		
		public function DynamicSimpleComparator( compareFunction:Function )
		{
			this.compareFunction = compareFunction;
		}	
		
		
		
		public function compare(value1:*, value2:*):ComparisonResult
		{
			var returnValue:* = compareFunction( value1, value2 );
			if ( returnValue is Bigger ) 	return ComparisonResults.BIGGER;
			if ( returnValue is Smaller ) 	return ComparisonResults.SMALLER;
			if ( returnValue is Equal ) 	return ComparisonResults.EQUAL;
			
			return ComparisonResults.DIFFERENT;
			
		}
		
	}
	
}